package com.shteo.crmd.admin.controller;

import com.shteo.crmd.admin.service.IGoodsService;
import com.shteo.crmd.common.source.AKResult;
import com.shteo.crmd.model.goods.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Akuma on 2016/10/16.
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private IGoodsService goodsService;

    /**
     * 添加商品
     * @param goods
     * @return
     */
    @RequestMapping("/add")
    public AKResult add(@RequestBody Goods goods){
        return goodsService.addGoods(goods);
    }

    /**
     * 查询商品集合
     * @return
     */
    @RequestMapping("/get")
    public List<Goods> get(){
        return goodsService.getAllGoods();
    }

    /**
     * 查询商品明细
     * @param goodsId 商品ID
     * @return
     */
    @RequestMapping("/getById")
    public Goods getGoodsById(@RequestParam("goodsId")Long goodsId){
        return goodsService.getGoodsById(goodsId);
    }

    /**
     * 删除商品
     * @param goodsId 商品ID
     * @return
     */
    @RequestMapping("/delById")
    public AKResult delGoodsById(@RequestParam("goodsId")Long goodsId){
        return goodsService.delGoodsById(goodsId);
    }

    /**
     * 更新商品
     * @param goods
     * @return
     */
    @RequestMapping("/updateById")
    public AKResult updateGoodsById(@RequestBody Goods goods){
        return goodsService.updateGoodsById(goods);
    }
}
